<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    v-for本身就有一个问题：就地复用，解决：添加一个唯一的key属性
    <div>
      <input type="text" v-model='val'><button @click='add'>添加</button>
      <ul v-for='(item,index) in arr' :key='item.index'>
        <li><input type="checkbox"> {{ item.name }} </li>
      </ul>
    </div>

  </div>
  <script src="../vue.js"></script>
  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        val: '',
        arr: [
          { id: 0, name: 'lili' },
          { id: 1, name: 'zhangsan' },
          { id: 2, name: 'zhaosi' }
        ]
      },
      methods: {
        add() {
          let obj = {
            id: new Date() * 1,
            name: this.val
          };
          // obj['id'] = new Date() * 1
          // obj['name'] = this.val
          this.arr.unshift(obj)
          // console.log(this.val);
        }
      }


    })
  </script>
</body>

</html>